package com.cluster.gulimall.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cluster.gulimall.common.utils.PageUtils;
import com.cluster.gulimall.common.utils.Query;
import com.cluster.gulimall.product.domain.vo.AttrGroupRelationVo;
import com.cluster.gulimall.product.entity.PmsAttrAttrgroupRelation;
import com.cluster.gulimall.product.mapper.PmsAttrAttrgroupRelationMapper;
import com.cluster.gulimall.product.service.AttrAttrgroupRelationService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


@Service("attrAttrgroupRelationService")
public class AttrAttrgroupRelationServiceImpl extends ServiceImpl<PmsAttrAttrgroupRelationMapper, PmsAttrAttrgroupRelation> implements AttrAttrgroupRelationService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<PmsAttrAttrgroupRelation> page = this.page(
                new Query<PmsAttrAttrgroupRelation>().getPage(params),
                new QueryWrapper<PmsAttrAttrgroupRelation>()
        );

        return new PageUtils(page);
    }

    /**
     * 批量添加属性与分组关联关系
     * @param vos
     */
    @Override
    public void saveBatch(List<AttrGroupRelationVo> vos) {

        List<PmsAttrAttrgroupRelation> collect = vos.stream().map((item) -> {
            PmsAttrAttrgroupRelation relationEntity = new PmsAttrAttrgroupRelation();
            BeanUtils.copyProperties(item, relationEntity);
            return relationEntity;
        }).collect(Collectors.toList());

        this.saveBatch(collect);


    }

}